{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 2: Environment Set up and Python Crash Course"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3.1. Writing Your First Program"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome to Data Visualization with Python\n"
     ]
    }
   ],
   "source": [
    "print(\"Welcome to Data Visualization with Python\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3.2. Python Variables and Data Types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n",
      "<class 'int'>\n",
      "<class 'float'>\n",
      "<class 'bool'>\n",
      "<class 'list'>\n",
      "<class 'tuple'>\n",
      "<class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "# A string Variable\n",
    "first_name = \"Joseph\" \n",
    "print(type(first_name))\n",
    "\n",
    "# An Integer Variable\n",
    "age = 20 \n",
    "print(type(age))\n",
    "\n",
    "# A floating point variable\n",
    "weight = 70.35\n",
    "print(type(weight))\n",
    "\n",
    "# A floating point variable\n",
    "married = False\n",
    "print(type(married))\n",
    "\n",
    "#List\n",
    "cars = [\"Honda\", \"Toyota\", \"Suzuki\"]\n",
    "print(type(cars))\n",
    "\n",
    "#Tuples\n",
    "days = (\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\")\n",
    "print(type(days))\n",
    "\n",
    "#Dictionaries\n",
    "days2 = {1:\"Sunday\", 2:\"Monday\", 3:\"Tuesday\", 4:\"Wednesday\", 5:\"Thursday\", 6:\"Friday\", 7:\"Saturday\"}\n",
    "print(type(days2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3.3. Python Operations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Arithmetic Operators"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30\n",
      "10\n",
      "200\n",
      "2.0\n",
      "10240000000000\n"
     ]
    }
   ],
   "source": [
    "X = 20 \n",
    "Y = 10 \n",
    "print(X + Y) \n",
    "print(X - Y) \n",
    "print(X * Y) \n",
    "print(X / Y) \n",
    "print(X ** Y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Logical Operators"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "X = True \n",
    "Y = False \n",
    "print(X and Y) \n",
    "print(X or Y) \n",
    "print(not(X and Y))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Comparison Operators"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "False\n",
      "True\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "X = 20\n",
    "Y = 35\n",
    "\n",
    "print(X == Y) \n",
    "print(X != Y) \n",
    "print(X > Y) \n",
    "print(X < Y) \n",
    "print(X >= Y) \n",
    "print(X <= Y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Assignment Operators"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30\n",
      "30\n",
      "10\n",
      "200\n",
      "2.0\n",
      "0\n",
      "10240000000000\n"
     ]
    }
   ],
   "source": [
    "X = 20; Y = 10\n",
    "R = X + Y \n",
    "print(R)\n",
    "\n",
    "X = 20; \n",
    "Y = 10 \n",
    "X += Y\n",
    "print(X)\n",
    "\n",
    "X = 20; \n",
    "Y = 10 \n",
    "X -= Y \n",
    "print(X) \n",
    "\n",
    "X = 20;\n",
    "Y = 10 \n",
    "X *= Y \n",
    "print(X)\n",
    "\n",
    "X = 20;\n",
    "Y = 10 \n",
    "X /= Y \n",
    "print(X) \n",
    "\n",
    "X = 20;\n",
    "Y = 10 \n",
    "X %= Y \n",
    "print(X) \n",
    "\n",
    "X = 20; \n",
    "Y = 10 \n",
    "X **= Y \n",
    "print(X)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Membership Operators"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "days = (\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\")\n",
    "print('Sunday' in days)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "days = (\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\")\n",
    "print('Xunday' not in days)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3.4. Conditional Statements"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ten is greater than 10\n"
     ]
    }
   ],
   "source": [
    "# The if statment\n",
    "\n",
    "if 10 > 5:\n",
    "    print(\"Ten is greater than 10\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 is greater than 5\n"
     ]
    }
   ],
   "source": [
    "# if-else statement\n",
    "\n",
    "if  5 > 10:\n",
    "    print(\"5 is greater than 10\")\n",
    "else:\n",
    "    print(\"10 is greater than 5\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5 is not greater than 10 and 8 is not smaller than 4\n"
     ]
    }
   ],
   "source": [
    "#if-elif and else\n",
    "\n",
    "if  5 > 10:\n",
    "    print(\"5 is greater than 10\")\n",
    "elif 8 < 4:\n",
    "    print(\"8 is smaller than 4\")\n",
    "else:\n",
    "    print(\"5 is not greater than 10 and 8 is not smaller than 4\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3.5. Iteration Statements"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "items = range(5)\n",
    "for item in items:\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "c = 0\n",
    "while c < 10:\n",
    "    print(c)\n",
    "    c = c +1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3.6. Functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This is a simple function\n"
     ]
    }
   ],
   "source": [
    "def myfunc():\n",
    "    print(\"This is a simple function\")\n",
    "    \n",
    "### function call\n",
    "myfunc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This is a function with parameter value: Parameter 1\n"
     ]
    }
   ],
   "source": [
    "def myfuncparam(num):\n",
    "    print(\"This is a function with parameter value: \"+num)\n",
    "    \n",
    "### function call\n",
    "myfuncparam(\"Parameter 1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This function returns a value\n"
     ]
    }
   ],
   "source": [
    "def myreturnfunc():\n",
    "    return \"This function returns a value\"\n",
    "\n",
    "val = myreturnfunc()\n",
    "print(val)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3.7. Objects and Classes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fruit has been eaten\n",
      "apple\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "class Fruit:\n",
    "    \n",
    "    name = \"apple\"\n",
    "    price = 10\n",
    "    \n",
    "    def eat_fruit(self):\n",
    "        print(\"Fruit has been eaten\")\n",
    "        \n",
    "\n",
    "f = Fruit()\n",
    "f.eat_fruit()\n",
    "print(f.name)\n",
    "print(f.price)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fruit has been eaten\n",
      "Orange\n",
      "15\n"
     ]
    }
   ],
   "source": [
    "class Fruit:\n",
    "    \n",
    "    name = \"apple\"\n",
    "    price = 10\n",
    "    \n",
    "    def __init__(self, fruit_name, fruit_price):\n",
    "        Fruit.name = fruit_name\n",
    "        Fruit.price = fruit_price\n",
    "        \n",
    "    def eat_fruit(self):\n",
    "        print(\"Fruit has been eaten\")\n",
    "        \n",
    "\n",
    "f = Fruit(\"Orange\", 15)\n",
    "f.eat_fruit()\n",
    "print(f.name)\n",
    "print(f.price)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercis 2.1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Which iteration should be used when you want to repeatedly execute a code specific number of times?\n",
    "\n",
    "A- For Loop \\\n",
    "B- While Loop \\\n",
    "C- Both A & B \\\n",
    "D- None of the above \n",
    "\n",
    "Answer: A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What is the maximum number of values that a function can return in Python?\n",
    "\n",
    "A- Single Value \\\n",
    "B- Double Value \\\n",
    "C- More than two values \\\n",
    "D- None\n",
    "\n",
    "Answer: C"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question 3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Which of the following membership operators are supported by Python?\n",
    "\n",
    "A- In \\\n",
    "B- Out \\\n",
    "C- Not In \\\n",
    "D- Both A and C \n",
    "\n",
    "Answer: D"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercis 2.2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Print the table of integer 9 using a while loop:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 x 1 = 9\n",
      "9 x 2 = 18\n",
      "9 x 3 = 27\n",
      "9 x 4 = 36\n",
      "9 x 5 = 45\n",
      "9 x 6 = 54\n",
      "9 x 7 = 63\n",
      "9 x 8 = 72\n",
      "9 x 9 = 81\n",
      "9 x 10 = 90\n"
     ]
    }
   ],
   "source": [
    "j=1\n",
    "while j< 11:\n",
    "    print(\"9 x \"+str(j)+ \" = \"+ str(9*j))\n",
    "    j=j+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
